package com.zzyl.nursing.controller.member;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.service.MemberOrdersProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author YH
 */
@RestController
@RequestMapping("/member/orders/project")
@Api(tags = "护理项目管理")
public class MemberOrdersProjectController {

    @Autowired
    private MemberOrdersProjectService memberOrdersProjectService;

    @GetMapping("/page")
    @ApiOperation("分页查询护理项目列表")
    public TableDataInfo<NursingProject> page(
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "status", required = false) Integer status) {

        // 1. 创建MP分页对象
        Page<NursingProject> page = new Page<>(pageNum, pageSize);

        // 2. 调用Service获取分页数据
        IPage<NursingProject> resultPage = memberOrdersProjectService.page(
                page, name, status);

        // 3. 转换为TableDataInfo格式
        TableDataInfo<NursingProject> result = new TableDataInfo<>(
                resultPage.getRecords(),
                (int) resultPage.getTotal()
        );
        result.setCode(200);
        result.setMsg("查询成功");

        return result;
    }

    @GetMapping("/{id}")
    @ApiOperation("根据编号查询护理项目信息")
    public AjaxResult getById(@PathVariable Integer id) {
        //使用MP实现
        NursingProject nursingProject = memberOrdersProjectService.getById(id);
        return AjaxResult.success(nursingProject);
    }

}
